package cn.com.ustudy.course.core.web.ctrl;

import cn.melonlib.download.comp.service.DownloadService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;

@RestController
@RequestMapping(path = "/file")
public class DownloadController {

    @Resource
    private DownloadService downloadService;

    @GetMapping(path = "download.api")
    public void download(HttpServletRequest request, HttpServletResponse response) throws Exception{
        File f=new File("D:\\video\\MP4\\20130530123246332_wmv.mp4");
        try(FileInputStream in=new FileInputStream(f)) {
            DownloadController.this.downloadService.download(request, response, f.getName(), f.length(), "video/mp4", in);
        }
    }
}
